﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Empresa.Sistema.Datos.Entidades;
using Empresa.Sistema.Aplicacion;

namespace Empresa.Sistema.Presentacion
{
    public partial class mntIdiomas : Form
    {

        #region "Instanciar"

        private static mntIdiomas m_FormDefInstance;
        public static mntIdiomas DefInstance
        {
            get
            {
                if (m_FormDefInstance == null || m_FormDefInstance.IsDisposed)
                    m_FormDefInstance = new mntIdiomas();
                return m_FormDefInstance;
            }
            set
            {
                m_FormDefInstance = value;
            }
        }

        #endregion 

        public mntIdiomas()
        {
            InitializeComponent();
        }

        List<Idioma> lista = new List<Idioma>();
        public Idioma idi;
        public string accion;

        private void btnAgregar_Click(object sender, EventArgs e)
        {
            accion = "adicionar";
            var regIdiomas = new regIdiomas();
            regIdiomas.Owner = this;
            regIdiomas.ShowDialog();
        }

        private void btnModificar_Click(object sender, EventArgs e)
        {
            accion = "modificar";
            var regIdiomas = new regIdiomas();
            regIdiomas.Owner = this;
            regIdiomas.ShowDialog();
        }

        private void btnEliminar_Click(object sender, EventArgs e)
        {
            accion = "eliminar";
            var regIdiomas = new regIdiomas();
            regIdiomas.Owner = this;
            regIdiomas.ShowDialog();
        }

        private void txtIdioma_TextChanged(object sender, EventArgs e)
        {
            lista = new Idiomas().ConsultaPorDescripcion(txtIdioma.Text);
            dgvIdiomas.AutoGenerateColumns = false;
            dgvIdiomas.DataSource = lista;
        }

        private void mntIdiomas_Load(object sender, EventArgs e)
        {
            lista = new Idiomas().Listar();
            dgvIdiomas.AutoGenerateColumns = false;
            dgvIdiomas.DataSource = lista;
        }

        private void dgvIdiomas_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvIdiomas.CurrentCell.RowIndex >= 0)
            {
                idi = (Idioma)lista[dgvIdiomas.CurrentCell.RowIndex];
            }
        }
    }
}
